home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Text⁄Files
/
Writeswell Jr. 1.0.2 Master
/
Writeswell Jr. Source
/
GenHandlers.c
< prev
next >
Wrap
Text File
|
1992-10-12
|
4KB
|
117 lines
/* GenHandlers.c
* Do the generic event handling according to Richard Clarke from Dev U.
* ©1992 Working Software, Inc.
* This source code is copyrighted. Permission is granted to use the Word Services
* portion of the Writeswell Jr. source code in your own programs, but you
* may not distribute the Writeswell Jr. word-processor code as a
* commercial product. If you modify the code, please do not call it
* Writeswell Jr. (or Writeswell.) This will ensure that people understand the
* program and don’t have to deal with a number of different versions with
* who-knows-what going on in the code.
*
* Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
* 18 Dec 91 Mike Crawford
*/
#include <AppleEvents.h>
#include <AEObjects.h>
#include <AERegistry.h>
#include "TBConstants.h"
#include "TBGlobals.h"
#include "GenHandlers.h"
#include "ObNull.h"
#include "ObWind.h"
#include "ObText.h"
#include "ObOspec.h"
#include "Gripe.h"
OSErr InitGenericHandlers( void )
{
OSErr err;
if ( err = AEInstallEventHandler( kAECoreSuite,
typeWildCard,
(EventHandlerProcPtr)GenericHandler,
0,
false ) ){
Gripe( "\poapp install failed" );
return err;
}
return err;
}
/* In the generic handler, we extract the direct object, resolve it, and identify
* the type of the finally resolved object (window, text, etc.). Then we call a routine
* that handles events for that kind of object.
*
* Note that this essentially circumvents the AppleEvent handler dispatch table, and
* replaces it with our own. The reason is that it makes it possible to have a separate
* source file for each kind of data object that will not need to be changed if other
* sorts of objects are added. If we have separate event handlers, then when we add
* an object, we will need to add the code to handle that object to each event handler.
* In this scheme, if we add support for a new kind of object, we add a source file
* full of handlers for that object, and add an entry (and a new #include line) in this
* file.
*
* This should make the code more maintainable. It would be real natural to use an
* object-oriented language here, where each object would have a standard set of methods
* for each event that all objects are supposed to handle.
*/
pascal OSErr GenericHandler( AppleEvent *theAppleEventPtr,
AppleEvent *replyEventPtr,
long refCon )
{
AEDesc paramDesc;
AEDesc tokenDesc;
OSErr err;
err = AEGetParamDesc( theAppleEventPtr,
keyDirectObject,
typeObjectSpecifier,
¶mDesc );
if ( err && err != errAEDescNotFound ){ /* It's OK for no parameter to be there */
/*Gripe( "\pAEGetParamDesc failed" );*/
return err;
}
if ( err != errAEDescNotFound ){
err = AEResolve( ¶mDesc,
kAEIDoMinimum,
&tokenDesc );
if ( err ){
return err;
}
}else{
/* Copy the null param to the token desc */
err = AEDuplicateDesc( ¶mDesc, &tokenDesc );
if ( err ){
Gripe( "\pAEDuplicateDesc failed" );
return err;
}
}
switch ( tokenDesc.descriptorType ){
case typeNull:
err = DispatchNull( &tokenDesc, theAppleEventPtr, replyEventPtr, refCon );
break;
case cWindow:
err = DispatchWind( &tokenDesc, theAppleEventPtr, replyEventPtr, refCon );
break;
case typeTEText:
err = DispatchTEText( &tokenDesc, theAppleEventPtr, replyEventPtr, refCon );
break;
case typeOSpecToken:
err = DispatchOspec( &tokenDesc, theAppleEventPtr, replyEventPtr, refCon );
break;
default:
Gripe( "\pUnknown object type" );
return errAEEventNotHandled;
}
return noErr;
}